package learn.advance.fileinputstream1;

import java.io.*;

class Demo1InputSteam {
    public static void Test() throws IOException {

        FileInputStream fis = new FileInputStream("D:\\workplace\\新建文件夹\\test\\a.txt");

        int len = fis.read();
        System.out.println(len);
        System.out.println("==============");

        len = fis.read();
        System.out.println(len);
        System.out.println("==============");

        while ((len = fis.read()) != -1) {
            System.out.println((char) (len));
        }

        fis.close();
    }
}

class Demo2InputStream {
    public static void Test() throws IOException {
        FileInputStream fis = new FileInputStream("D:\\workplace\\新建文件夹\\test\\a.txt");
        byte[] bytes = new byte[1024];
        int len = 0;
        while ((len = fis.read(bytes)) != -1) {
            System.out.println(new String(bytes, 0, len));
        }

        fis.close();
    }
}

class Demo1CopyFile {
    public static void Test() throws IOException {
        long s = System.currentTimeMillis();

        FileInputStream fis = new FileInputStream("D:\\workplace\\新建文件夹\\test\\a.txt");
        FileOutputStream fos = new FileOutputStream("D:\\workplace\\新建文件夹\\test\\a.txt");

//        File f = new File("D:\\workplace\\新建文件夹\\test\\b.txt");
//        f.createNewFile();
//
//        FileOutputStream fos = new FileOutputStream(f);
//
//        byte[] bytes = new byte[1024];
//        int len = 0;
//
//        //  while ((len = fis.read(bytes)) != -1)
//
//        while ((len = fis.read(bytes)) != -1) {
//            System.out.println(new String(bytes, 0, len));
//            fos.write(bytes, 0, len);
//        }


//        fos.close();
//        fis.close();
//
//        long e = System.currentTimeMillis();
//        System.out.println("total:" + (e - s));
    }
}


public class TestFileInputStream {
    public static void main(String[] args) throws IOException {
        // Demo1InputSteam.Test();
        //Demo2InputStream.Test();
        Demo1CopyFile.Test();
    }
}


